package com.by.zhdoctor.huanxin.api.impl;

import com.by.zhdoctor.huanxin.api.FileApi;
import com.by.zhdoctor.huanxin.util.HuanXinInfo;
import com.by.zhdoctor.huanxin.util.ResponseHandler;
import com.by.zhdoctor.huanxin.util.TokenUtil;
import io.swagger.client.ApiResponse;
import io.swagger.client.api.UploadAndDownloadFilesApi;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.File;

/**
 * 文件上传下载api调用实现类
 * Created by succy on 17-9-3.
 */
@Service
public class FileApiImpl implements FileApi {
    @Autowired
    private ResponseHandler responseHandler;

    private UploadAndDownloadFilesApi api = new UploadAndDownloadFilesApi();

    @Override
    public ApiResponse<?> upload(final File file) {
        return responseHandler.handle(() ->
            api.orgNameAppNameChatfilesPostWithHttpInfo(HuanXinInfo.ORG_NAME, HuanXinInfo.APP_NAME, TokenUtil.getAccessToken(), file, true));
    }

    @Override
    public ApiResponse<?> download(final String fileUUID, final String shareSecret, final boolean isThumbnail) {
        return responseHandler.handle(() ->
            api.orgNameAppNameChatfilesUuidGetWithHttpInfo(HuanXinInfo.ORG_NAME, HuanXinInfo.APP_NAME, TokenUtil.getAccessToken(), fileUUID, shareSecret, isThumbnail));
    }
}
